<?php

namespace app\model;

use think\Model;

class Admin extends Model
{
    protected $name = "admin";
    const IS_DELETE_NO = 0;
    const SUPPER_ADMIN = [1,2];

    /**
     * @Description 检查数据是否存在
     * @author: zj
     * @param int $id
     * @time 2024/07/09 15:36:12
     * @return false|mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function checkIsExist(int $id)
    {
        $info = $this->field('id')
            ->where('id',$id)
            ->where('delete_time',self::IS_DELETE_NO)
            ->find();
        if (!$info) {
            return false;
        }

        return $info['id'];
    }

    /**
     * @Description 检查用户名是否存在
     * @author: zj
     * @param string $name
     * @time 2024/07/09 15:38:55
     * @return false|mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function checkNameIsExist(string $name)
    {
        $info = $this->field('id')
            ->where('name',$name)
            ->where('delete_time',self::IS_DELETE_NO)
            ->find();
        if (!$info) {
            return false;
        }

        return $info['id'];
    }

    /**
     * @Description 判断手机号码是否存在
     * @author: zj
     * @param string $phone
     * @time 2024/07/09 15:40:20
     * @return false|mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function checkPhoneIsExist(string $phone)
    {
        $info = $this->field('id')
            ->where('phone',$phone)
            ->where('delete_time',self::IS_DELETE_NO)
            ->find();
        if (!$info) {
            return false;
        }

        return $info['id'];
    }

}